//
//  HTClassTextFieldView.swift
//  QuitSmokingApp
//  
//  Created by wealon on 2024.
//  QuitSmokingApp.
//  
    

import UIKit

class HTClassTextFieldView: UIView {
    lazy var var_textField: UITextField = {
        let var_textField = UITextField()
        var_textField.textColor = .white
        var_textField.textAlignment = .right
        var_textField.font = .systemFont(ofSize: 14, weight: .medium)
        return var_textField
    }()
    
    lazy var var_titleLabel: UILabel = {
        let var_label = UILabel()
        var_label.textColor = UIColor("#BABABA")
        var_label.font = .systemFont(ofSize: 14, weight: .medium)
        return var_label
    }()
    
    lazy var var_unitLabel: UILabel = {
        let var_label = UILabel()
        var_label.textColor = .white
        var_label.font = .systemFont(ofSize: 14, weight: .medium)
        return var_label
    }()
    
    lazy var var_button: UIButton = {
        let var_bu = UIButton()
        var_bu.backgroundColor = .clear
        var_bu.onTap { [weak self] in
            self?.BLOCK_tapBLOCK?()
        }
        return var_bu
    }()
    
    var BLOCK_tapBLOCK: (() -> Void)? {
        didSet {
            var_button.isHidden = BLOCK_tapBLOCK == nil
        }
    }
    
    private lazy var var_line: UILabel = {
        let var_label = UILabel()
        var_label.backgroundColor = UIColor("#464646")
        return var_label
    }()
    
    var var_isLine = true {
        didSet {
            var_line.isHidden = !var_isLine
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        ht_setUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func ht_setUI() {
        self.addSubview(var_titleLabel)
        self.addSubview(var_textField)
        self.addSubview(var_unitLabel)
        self.addSubview(var_line)
        self.addSubview(var_button)
        var_titleLabel.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(14.auto())
            make.centerY.equalToSuperview()
        }
        
        var_unitLabel.snp.makeConstraints { make in
            make.right.equalToSuperview().offset(-14.auto())
            make.centerY.equalToSuperview()
        }
        var_textField.snp.makeConstraints { make in
            make.top.bottom.equalToSuperview()
            make.width.equalTo(200.auto())
            make.right.equalTo(var_unitLabel.snp.left)
        }
        
        var_line.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(14.auto())
            make.right.equalToSuperview().offset(-14.auto())
            make.bottom.equalToSuperview()
            make.height.equalTo(1)
        }
        
        var_button.snp.makeConstraints { make in
            make.edges.equalTo(var_textField)
        }
        var_button.isHidden = true
    }
}
